package com.tuanda.app.customviewdemo.cavans;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/19.
 */
public class DrawArcView extends View {
    private Paint mPaint;
    public DrawArcView(Context context) {
        this(context,null);
    }

    public DrawArcView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DrawArcView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.GRAY);

        canvas.drawArc(50,50,200,120,-60,60,true,mPaint);

        RectF rectF = new RectF(100,130,500,280);
        canvas.drawArc(rectF,-120,100,true,mPaint);
        canvas.drawArc(rectF,30,120,false,mPaint);
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawArc(rectF,180,50,false,mPaint);
    }
}
